package com.ubireality.repository;

import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.transaction.Transactional;
import javax.ws.rs.Path;

import com.mysema.query.types.Predicate;
import com.mysema.query.types.Projections;

import static com.ubireality.module.player.QUser.user;

import com.ubireality.module.player.QUser;
import com.ubireality.module.player.User;

@Transactional
@RequestScoped
@Path("UserRepository")
public class UserRepository extends AbstractRepository<User> {

	@Override
	public User findById(Long id) {
		return find(User.class, id);
	}

	/* return the persistent object */
	public User save(User user) {
		return persistOrMerge(user);
	}

	/* find with predicate */
	public List<User> findAll(Predicate expr) {
		return from(user).where(expr).list(
				Projections.bean(User.class, user.name, user.deviceId));
	}

	/* get all */
	public List<User> all() {
		return from(user).list(
				Projections.bean(User.class, user.name, user.deviceId));
	}
}
